package com.heima.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeAdvice {

    @Pointcut("execution(* com.heima.dao.BookDao.save(..))")
    public void as(){}

    @Around("as()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //环绕前
        long starttime = System.currentTimeMillis();

        for (int i = 0; i < 10000; i++) {
            pjp.proceed();
        }

        //环绕后
        long endtime = System.currentTimeMillis();

        String methodName = pjp.getSignature().getName();
        String className = pjp.getSignature().getDeclaringTypeName();

        System.out.println("执行方法为" + className + "," + methodName +
                "执行时间为" + (endtime-starttime) + "ms");

        return null;
    }
}
